]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
telepathyClient: Gracefully handle missing telepathy deps
authorFlorian Müllner <fmuellner@gnome.org>
Fri, 10 Mar 2017 17:23:20 +0000 (18:23 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Mon, 13 Mar 2017 15:23:08 +0000 (16:23 +0100)
Telepathy's role has been diminishing continuously over the last
couple of years, so while chat integration is a nice feature for
those who use it, it is hard to justify keeping it as a hard
dependency. To address this, split out the component from the
client so we can handle missing typelibs gracefully by not
providing any chat integration.

https://bugzilla.gnome.org/show_bug.cgi?id=779878

js/ui/components/telepathyClient.js

index f6575ebfcebbcf9db93aa6c3be0960d32cae5303..e0a388be67c9c3d7d1036852b01723c0920229f3 100644 (file)
@@ -8,8 +8,15 @@ const Lang = imports.lang;
 const Mainloop = imports.mainloop;
 const Signals = imports.signals;
 const St = imports.gi.St;
-const Tpl = imports.gi.TelepathyLogger;
-const Tp = imports.gi.TelepathyGLib;
+
+var Tpl = null;
+var Tp = null;
+try {
+    Tpl = imports.gi.TelepathyLogger;
+    Tp = imports.gi.TelepathyGLib;
+} catch(e) {
+    log('Telepathy is not available, chat integration will be disabled.');
+}
 
 const History = imports.misc.history;
 const Main = imports.ui.main;
@@ -19,6 +26,8 @@ const Params = imports.misc.params;
 const PopupMenu = imports.ui.popupMenu;
 const Util = imports.misc.util;
 
+const HAVE_TP = (Tp != null && Tpl != null);
+
 // See Notification.appendMessage
 const SCROLLBACK_IMMEDIATE_TIME = 3 * 60; // 3 minutes
 const SCROLLBACK_RECENT_TIME = 15 * 60; // 15 minutes
@@ -70,7 +79,41 @@ function makeMessageFromTplEvent(event) {
     };
 }
 
-const TelepathyClient = new Lang.Class({
+const TelepathyComponent = new Lang.Class({
+    Name: 'TelepathyComponent',
+
+    _init: function() {
+        this._client = null;
+
+        if (!HAVE_TP)
+            return; // Telepathy isn't available
+
+        this._client = new TelepathyClient();
+    },
+
+    enable: function() {
+        if (!this._client)
+            return;
+
+        try {
+            this._client.register();
+        } catch (e) {
+            throw new Error('Couldn\'t register Telepathy client. Error: \n' + e);
+        }
+
+        if (!this._client.account_manager.is_prepared(Tp.AccountManager.get_feature_quark_core()))
+            this._client.account_manager.prepare_async(null, null);
+    },
+
+    disable: function() {
+        if (!this._client)
+            return;
+
+        this._client.unregister();
+    }
+});
+
+const TelepathyClient = HAVE_TP ? new Lang.Class({
     Name: 'TelepathyClient',
     Extends: Tp.BaseClient,
 
@@ -117,21 +160,6 @@ const TelepathyClient = new Lang.Class({
             Lang.bind(this, this._delegatedChannelsCb));
     },
 
-    enable: function() {
-        try {
-            this.register();
-        } catch (e) {
-            throw new Error('Couldn\'t register Telepathy client. Error: \n' + e);
-        }
-
-        if (!this._accountManager.is_prepared(Tp.AccountManager.get_feature_quark_core()))
-            this._accountManager.prepare_async(null, null);
-    },
-
-    disable: function() {
-        this.unregister();
-    },
-
     vfunc_observe_channels: function(account, conn, channels,
                                      dispatchOp, requests, context) {
         let len = channels.length;
@@ -250,7 +278,7 @@ const TelepathyClient = new Lang.Class({
         // Nothing to do as we don't make a distinction between observed and
         // handled channels.
     },
-});
+}) : null;
 
 const ChatSource = new Lang.Class({
     Name: 'ChatSource',
@@ -968,4 +996,4 @@ const ChatNotificationBanner = new Lang.Class({
     }
 });
 
-const Component = TelepathyClient;
+const Component = TelepathyComponent;